4.4 Board

You can consider Board as a plaque that has the generic features of the object. Indeed the Board class is derived from the plaque and object base classes. The main destination of Board Objects is to provide panels for forming more complicated constructions, consisting of Indicators, buttons, Graphs and so on. This allows to manipulate the whole construction as an integral object.

Constructor:

Board(
int x0,int y0, // coord. of LEFT-TOP corner of Board
objtype type, // may be FIXED, PERM, POPUP
char * title, // title of Board
int xlength,int ylength,// size of board
//———- Hereafter are defaults
// proc supplied by programmer to repaint Board,
void (far * paintproc)()=procNULL,// only for PERM indicators
int titlefont=0,int titlefontsize=1,// font for title
COLORS titlecolor=RED, // color of title
plaquecolors brdcolcnfg=plaquecoldflt);//colors of Board

All parameters here are familiar except xlength and ylength. These parameters define the size of Board in VGA pixels. Sizes of other Objects are calculated by Virtual Panels automatically and depend on types and sizes of fonts, formats and so on. The advantage of the direct size definition is that the real size of Object in this case doesn't depend on the aspect ratio of current graphics mode. You can set xlength and ylength zero if you don't know at the moment the size of the Board, and set it later using method ChangeSize.

Data members:

Includes data members inherited from the object base class (sect.4).

int y0p;

The upper y location above which area occupied by Board's title starts. Can be used for disposing Objects on the Board. See example below.

Methods:

Includes methods inherited from the object base class (sect.4).

virtual void Paint(void);

Paints Board.

void ChangeSize( int xlength, int ylength);

You can set vertical and horizontal lengths of Board zero if you don't know at the moment the size of the Board, and change them later using this method. Such situation occurs because Virtual Panels automatically calculates sizes of other Objects. You cannot know in advance the required size of the Board, when the Objects to be put on the Board, are declared after the Board. In the following example the Board _Hysteresis represents the panel with indicators and button system. The panel _Hysteresis is declared in the main function, while indicators and buttons are declared separately in button procedure. Of course _Hysteresis could also be declared in that procedure, but then it would be inaccessible to the main Loop function in the main function and you could not , for example, drag it on the screen. To be accessible to the Loop function the Object must be declared before that function.
Example 4.4.1:

#include <vphead.h>     // must be included first
#pragma hdrstop         // stop precompiling headers

#include <vpbase.h>     // Virtual Panels header files
#include <vpboard.h>
#include <vpindic.h>
#include <vpbutt.h>

#include "rt.h"         // users definitions

// Global pointers.
// Are necessary for an access to Objects from button procedures
Board *pbdHysteresis;   // panel declared in main()
Indicator<int> *pindAC, *pindLimDC;// indicators declared in bpHyst()

void far bpHyst(void)   // button procedure declaration

main
{InitAndCopyright("* Board example *" );
 butsystem bsMain( MASTER ); //install Main button system
 .
 .
           //----------- HYSTERESIS PANEL ------
Board bdHysteresis(x0s,y0s,POPUP,"Hysteresis measurement",
                  0,0,bpHyst );// size of board is while zero

pbdHysteresis=&bdHysteresis;    // global pointer
 .
 .
           //---------- MAIN BUTTON SYSTEM -----
 butgrp HorizButtons( 3, maxy-25, 70, 21, HORIZ, 2);
  button butQuit("Quit",'Q','q',bpQuit,0,1,quittexcol,quitbutcol);
  button butHyst( "hYster", 'Y','y', bpHyst);
 .
 .
 bsMain.Loop(MainBackgr); // main Loop
 bpQuit();                // quit application
}
//------------------------ HYST BUTTON PROCEDURE -------------------
//-- POPUP panel with two indicators and buttons associated with them.
//-- Indicators shows current values of parameters - value of AC
//-- current and limit of DC current. Pushing buttons calls button
//-- procedures that allow you to change current values of parameters.

void far bpHyst(void)
{
butsystem bsHyst;       // install new button system

int indy0 = pbdHysteresis->y0p; // TOP coord. of indicators

         //--------------- Indicators ------

Indicator<int>//-- x0 --- y0 - type - title - width - var - format --
 indAC( Hysteresis->x0, indy0, FIXED, "AC",       5, &altI, "%d"),
 indLimDC( _indAC.xmax, indy0, FIXED, "DC limit", 5, &limDC, "%d");

 pindAC1=&indAC1;  pindLimDC=&indLimDC; // global pointers

        //---------------- Buttons ------
#define SHIFT   10      // shift between buttons
int                     // length of button
 length = indLimDC.xmax - indLimDC.x0 - SHIFT;

butgrp gr( Hysteresis->x0 + SHIFT/2, _indAC1.ymax, length , 18,
                                                 HORIZ, SHIFT);
  button butAD1(      "AC", 'A','a', bpAC1,   SMALL_FONT, 4);
  button butLimDC( "Limit", 'L','l', bpLimDC, SMALL_FONT, 4);

       //-- Now all sizes have been calculated and we can
       //-- set the right size of the Hysteresis panel
       //-- and paint the panel with all details on it.
pbdHysteresis->ChangeSize(indLimDC.xmax - pbdHysteresis->x0,
                        indLimDC.ymax - pbdHysteresis->y0 + SHIFT);

       //---------------- Paint the whole board
pbdHysteresis->Paint(); // paint panel first
indAC.Paint();          // then indicators
indLimDC.Paint();
gr.Paint();             //      and buttons
              // After that display values of
indAC.Refresh();        //      AC current
indLimDC.Refresh();     //      limit of DC current

       //-- Here program enters into the new Virtual Panels Loop.
       //-- HystBackgr deals with measurements. Pushing buttons
       //-- on the panel you stop measurements and can change
       //-- parameters of system. You cannot leave the measurement
       //-- until measInProgress flag is set FALSE from HystBackgr.
do
 bsHyst.Loop(HystBackgr);
while(measInProgress);

 pbdHysteresis->Remove();  //  Remove Hysteresis panel from the screen,
 pbdHysteresis->MkActive();//  but put it on the top of Stack of Object
                           //  to be able to relocate it if necessary.
 object::RepaintScr();     //  Before leaving restore the screen.
}

This example is a simplified fragment of a real application. Besides ChangeSize method it illustrates the use of many other Objects and methods we have described till now. We recommend to read this fragment carefully, paying attention to the comments, to understand the style of programming Virtual Panels applications.